﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing.Design;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Windows.Forms.Design;

namespace MidasPoster
{
    public class PropertyGridFileItem : UITypeEditor
    {

        public override UITypeEditorEditStyle GetEditStyle(System.ComponentModel.ITypeDescriptorContext context)
        {

            return UITypeEditorEditStyle.Modal;

        }

        public override object EditValue(System.ComponentModel.ITypeDescriptorContext context, System.

IServiceProvider provider, object value)
        {

            IWindowsFormsEditorService edSvc =

(IWindowsFormsEditorService)provider.GetService(typeof(IWindowsFormsEditorService));

            if (edSvc != null)
            {

                // 可以打开任何特定的对话框  

                OpenFileDialog dialog = new OpenFileDialog();

                dialog.AddExtension = false;

                if (dialog.ShowDialog().Equals(DialogResult.OK))
                {

                    return dialog.FileName;

                }

            }

            return value;

        }

    }  

        /// <summary>
        /// PropertyGridMutiText 的摘要说明。
        /// </summary>

        public class PropertyGridRichText : UITypeEditor
        {

            public override UITypeEditorEditStyle GetEditStyle(System.ComponentModel.ITypeDescriptorContext context)
            {

                return UITypeEditorEditStyle.DropDown;

            }

            public override object EditValue(System.ComponentModel.ITypeDescriptorContext context, System.IServiceProvider provider, object value)
            {

                try
                {

                    IWindowsFormsEditorService edSvc =

    (IWindowsFormsEditorService)provider.GetService(typeof(IWindowsFormsEditorService));

                    if (edSvc != null)
                    {

                        if (value is string)
                        {

                            RichTextBox box = new RichTextBox();

                            box.Text = value as string;

                            edSvc.DropDownControl(box);

                            return box.Text;

                        }

                    }

                }

                catch (Exception ex)
                {

                    System.Console.WriteLine("PropertyGridRichText Error : " + ex.Message);

                    return value;

                }

                return value;

            }

        

    } 


    public class FileNameConverter : StringConverter
    {
        public override bool GetStandardValuesSupported(ITypeDescriptorContext context)
        {
            return true;
        }
        public override StandardValuesCollection GetStandardValues(ITypeDescriptorContext context)
        {
            return new StandardValuesCollection(new string[] { "新文件", "文件1", "文档1" });
        }
        public override bool GetStandardValuesExclusive(ITypeDescriptorContext context)
        {
            return false;
        }
    }
}
